package com.briup.cms.web.controller;

import com.briup.cms.aop.Logging;
import com.briup.cms.bean.BaseConfig;
import com.briup.cms.service.IBaseConfigService;
import com.briup.cms.utils.Message;
import com.briup.cms.utils.MessageUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/auth/config")
@Api(tags = "系统配置相关接口")
public class BaseConfigController {
    @Autowired
    private IBaseConfigService service;

    @GetMapping("/current/config/yes")
    @ApiOperation("查找当前启用的系统配置")
    public Message ConfigNow()
    {
        BaseConfig baseConfig = service.ConfigNow();
        return MessageUtil.success(baseConfig);
    }
    @Logging
    @ApiImplicitParams({@ApiImplicitParam(name="id",
                                          value="主键",
                                          paramType="query",
                                          required=true)})
    @DeleteMapping("deleteById")
    @ApiOperation("通过id删除配置信息")
    public  Message delete(int id){
        service.delete(id);
        return MessageUtil.success("删除成功");
    }

    @ApiOperation(value = "查找所有配置信息", notes="分页查询,请输入当前页和每页大小")
    @GetMapping("/page/query")
    public Message findAll(int pageNum,int pageSize){
        PageInfo<BaseConfig> d = service.findAll(pageNum,pageSize);
        return MessageUtil.success(d);
    }
    @Logging
    @PostMapping("/save")//ok
    @ApiOperation("保存配置信息")
    public Message insert(BaseConfig config){
        service.insert(config);
        return MessageUtil.success(config);
    }
    @Logging
    @PutMapping("/update")//ok
    @ApiOperation("更新配置")
    public Message update(BaseConfig config){
        service.update(config);
        return MessageUtil.success();
    }
    @Logging
    @ApiImplicitParams({@ApiImplicitParam(name="id",
                                          value="主键",
                                          paramType="query",
                                          required=true),
                        @ApiImplicitParam(name="status",
                                          value="状态，0-禁用，1-启用",
                                          paramType="query",
                                          required=true)})
    @PutMapping("/update/status")
    @ApiOperation("更新配置信息状态")
    public Message changeStatus(int id,int status){
        service.changeStatus(id,status);
        return MessageUtil.success("配置信息状态修改成功");
    }

}
